package cn.guozeyiblog.client;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.guozeyiblog.blogutils.Link;

public class LinkAdapter extends BaseAdapter {
	
	private Context context;
	private LayoutInflater inflater;
	private List<Link> listdata;

	public LinkAdapter(List<Link> listdata,Context context) {
		// TODO Auto-generated constructor stub
		this.listdata = listdata;
		this.context = context;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listdata.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listdata.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("ViewHolder")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LinearLayout layout = null;
		if (convertView==null) {
			layout = (LinearLayout) inflater.inflate(R.layout.link_item, null);
		}else {
			layout = (LinearLayout) convertView;
		}
		((TextView)layout.findViewById(R.id.link_text)).setText(listdata.get(position).getName());
		return layout;
	}

}
